/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package formula.one.urjc.piloto.view;

import formula.one.urjc.Metodos;
import formula.one.urjc.dueño.view.ventanaAviso;
import formula.one.urjc.piloto.CaracteristicasTecnicas;
import formula.one.urjc.piloto.DatosPersonales;
import formula.one.urjc.piloto.Piloto;
import java.util.ArrayList;

/**
 *
 * @author santiago
 */
public final class ModificarPiloto extends javax.swing.JInternalFrame {
    
    //VARIABLES GLOBALES
    //Declaramos este objeto para ejecutar los metodos genericos
    Metodos metodo = new Metodos() ;
    String nombreFichero = "pilotos.dat" ;
    ArrayList<Object> arrayPilotos = metodo.leerFichero(nombreFichero) ;
    int longitudArray = arrayPilotos.size() ;

    /**
     * Creates new form ModificarPIloto
     */
    public ModificarPiloto() {
        initComponents(); 
        cargarPilotos() ;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        pilotos = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        nombrePiloto = new javax.swing.JTextField();
        apellidosPiloto = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        edadPiloto = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        alturaPiloto = new javax.swing.JTextField();
        pesoPiloto = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        valoracionPiloto = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        puntosPiloto = new javax.swing.JTextField();
        sueldoPiloto = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        modificarPiloto = new javax.swing.JButton();
        cancelarModificacion = new javax.swing.JButton();
        jTextReflejos = new javax.swing.JTextField();
        jTextAgresividad = new javax.swing.JTextField();
        jTextPaciencia = new javax.swing.JTextField();
        jTextValentia = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setText("Modificar Piloto");

        jLabel2.setText("Piloto:");

        pilotos.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                pilotosItemStateChanged(evt);
            }
        });

        jLabel3.setText("Nombre:");

        nombrePiloto.setEnabled(false);

        apellidosPiloto.setEnabled(false);

        jLabel4.setText("Datos Personales:");

        jLabel5.setText("Apellidos:");

        jLabel6.setText("Edad:");

        edadPiloto.setEnabled(false);

        jLabel7.setText("Altura:");

        alturaPiloto.setEnabled(false);

        pesoPiloto.setEnabled(false);

        jLabel8.setText("Peso:");

        jLabel9.setText("Características Técnicas:");

        jLabel10.setText("Reflejos:");

        jLabel11.setText("Agresividad: ");

        jLabel12.setText("Paciencia: ");

        jLabel13.setText("Valentía: ");

        valoracionPiloto.setEnabled(false);

        jLabel14.setText("Valoración:");

        puntosPiloto.setEnabled(false);

        sueldoPiloto.setEnabled(false);

        jLabel15.setText("Puntos:");

        jLabel16.setText("Sueldo:");

        modificarPiloto.setText("Modificar");
        modificarPiloto.setEnabled(false);
        modificarPiloto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                modificarPilotoActionPerformed(evt);
            }
        });

        cancelarModificacion.setText("Cancelar");
        cancelarModificacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelarModificacionActionPerformed(evt);
            }
        });

        jTextReflejos.setEnabled(false);
        jTextReflejos.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextReflejosFocusLost(evt);
            }
        });

        jTextAgresividad.setEnabled(false);
        jTextAgresividad.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextAgresividadFocusLost(evt);
            }
        });

        jTextPaciencia.setEnabled(false);
        jTextPaciencia.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextPacienciaFocusLost(evt);
            }
        });

        jTextValentia.setEnabled(false);
        jTextValentia.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextValentiaFocusLost(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(nombrePiloto, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(apellidosPiloto, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(66, 66, 66)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pilotos, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(145, 145, 145)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(jLabel4))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(35, 35, 35)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(12, 12, 12)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(21, 21, 21)
                                        .addComponent(modificarPiloto)
                                        .addGap(18, 18, 18)
                                        .addComponent(cancelarModificacion))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                .addComponent(jLabel13)
                                                .addGap(34, 34, 34)
                                                .addComponent(jTextValentia))
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                        .addGroup(layout.createSequentialGroup()
                                                            .addComponent(jLabel10)
                                                            .addGap(38, 38, 38))
                                                        .addGroup(layout.createSequentialGroup()
                                                            .addComponent(jLabel11)
                                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                                                    .addComponent(jLabel12))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(jTextPaciencia, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                        .addComponent(jTextAgresividad)
                                                        .addComponent(jTextReflejos, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                .addComponent(jLabel15)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(puntosPiloto, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                        .addGap(28, 28, 28)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(12, 12, 12)
                                                .addComponent(jLabel14))
                                            .addComponent(sueldoPiloto, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(22, 22, 22)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(valoracionPiloto, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jLabel16)))))))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel8)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel7))
                                .addGap(23, 23, 23)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(pesoPiloto)
                                    .addComponent(edadPiloto)
                                    .addComponent(alturaPiloto, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(pilotos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(nombrePiloto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(apellidosPiloto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel4)
                        .addGap(12, 12, 12)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(edadPiloto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(alturaPiloto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(pesoPiloto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8))
                        .addGap(18, 18, 18)
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jTextReflejos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jTextAgresividad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel11))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(34, 34, 34)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jTextPaciencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel12))))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel13)
                            .addComponent(jTextValentia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(puntosPiloto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel15))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 215, Short.MAX_VALUE)
                        .addComponent(jLabel14)
                        .addComponent(valoracionPiloto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(5, 5, 5)
                        .addComponent(jLabel16)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(sueldoPiloto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(70, 70, 70)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(modificarPiloto)
                    .addComponent(cancelarModificacion))
                .addContainerGap(26, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cancelarModificacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarModificacionActionPerformed
        // TODO add your handling code here:
        this.dispose() ;
    }//GEN-LAST:event_cancelarModificacionActionPerformed

    private void pilotosItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_pilotosItemStateChanged
        // TODO add your handling code here:
        String buscarPiloto = (String) pilotos.getSelectedItem() ;
        // Longitud del array de Pilotos
        System.out.println("Longitud de Array: " + longitudArray) ;
        boolean encontrado = false ;
        for (int j=0; j<longitudArray; j++) {
            Piloto pilotoLista = (Piloto) arrayPilotos.get(j) ;
            String nombre_Piloto = pilotoLista.getNombre() ;
            String apellidos_Piloto = pilotoLista.getApellidos() ;
            String nombreCompleto = nombre_Piloto + " " + apellidos_Piloto ;
            encontrado = nombreCompleto.equals(buscarPiloto) ;
            if (encontrado) {
                System.out.println("Encontrado");
                nombrePiloto.setText(pilotoLista.getNombre()) ;
                apellidosPiloto.setText(pilotoLista.getApellidos()) ;
                edadPiloto.setText(Integer.toString(pilotoLista.getDatosPersonales().getEdad())) ;
                edadPiloto.setEnabled(true) ;
                alturaPiloto.setText(Double.toString(pilotoLista.getDatosPersonales().getAltura())) ;
                alturaPiloto.setEnabled(true) ;
                pesoPiloto.setText(Double.toString(pilotoLista.getDatosPersonales().getPeso())) ;
                pesoPiloto.setEnabled(true) ;
                jTextReflejos.setText(Double.toString(pilotoLista.getCaracteristicasTecnicas().getReflejos()));
                jTextReflejos.setEnabled(true);
                //reflejosPiloto.setSelectedItem(Double.toString(pilotoLista.getCaracteristicasTecnicas().getReflejos())) ;
                jTextAgresividad.setText(Double.toString(pilotoLista.getCaracteristicasTecnicas().getAgresividad()));
                jTextAgresividad.setEnabled(true);
                //reflejosPiloto.setEnabled(true) ;
                //agresividadPiloto.setSelectedItem(Double.toString(pilotoLista.getCaracteristicasTecnicas().getAgresividad())) ;
                //agresividadPiloto.setEnabled(true) ;
                jTextPaciencia.setText(Double.toString(pilotoLista.getCaracteristicasTecnicas().getPaciencia()));
                jTextPaciencia.setEnabled(true);
                //pacienciaPiloto.setSelectedItem(Double.toString(pilotoLista.getCaracteristicasTecnicas().getPaciencia())) ;
                //pacienciaPiloto.setEnabled(true) ;
                jTextValentia.setText(Double.toString(pilotoLista.getCaracteristicasTecnicas().getValentia()));
                jTextValentia.setEnabled(true);
                //valentiaPiloto.setSelectedItem(Double.toString(pilotoLista.getCaracteristicasTecnicas().getValentia())) ;
                //valentiaPiloto.setEnabled(true) ;
                valoracionPiloto.setText(String.format("%.1f",pilotoLista.getValoracion())) ;
                puntosPiloto.setText(Integer.toString(pilotoLista.getPuntos())) ;
                puntosPiloto.setEnabled(true) ;
                sueldoPiloto.setText(String.format("%.1f",pilotoLista.getSueldo())) ;
                modificarPiloto.setEnabled(true) ;
            }
            obtenerValoracion();
        }
    }//GEN-LAST:event_pilotosItemStateChanged

    private void modificarPilotoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_modificarPilotoActionPerformed
        // TODO add your handling code here:
        // Declaramos las variables con los valores del formulario
        String nombre_Piloto = nombrePiloto.getText() ;
        String apellidos_Piloto = apellidosPiloto.getText() ;
        try{
        int edad_Piloto = Integer.parseInt(edadPiloto.getText()) ;
        double altura_Piloto = Double.parseDouble(alturaPiloto.getText()) ;
        double peso_Piloto = Double.parseDouble(pesoPiloto.getText()) ;
        double reflejos_Piloto = Double.parseDouble(jTextReflejos.getText()) ;
        double agresividad_Piloto = Double.parseDouble(jTextAgresividad.getText()) ;
        double paciencia_Piloto = Double.parseDouble(jTextPaciencia.getText()) ;
        double valentia_Piloto = Double.parseDouble(jTextValentia.getText()) ;
        //double valoracion_Piloto = Double.parseDouble(valoracionPiloto.getText()) ;
        int puntos_Piloto = Integer.parseInt(puntosPiloto.getText()) ;
        //double sueldo_Piloto = Double.parseDouble(sueldoPiloto.getText()) ;        
        //
        if(reflejos_Piloto<=5 && reflejos_Piloto>=0 && agresividad_Piloto<=5 && agresividad_Piloto>=0 && paciencia_Piloto<=5 && paciencia_Piloto>=0 && valentia_Piloto<=5 && valentia_Piloto>=0){
        // Declaramos el objeto Datos Personales
        DatosPersonales datos_Personales = new DatosPersonales (edad_Piloto,
                                                                altura_Piloto,
                                                                peso_Piloto) ;
        // Declaramos el objeto Caracteristicas Técnicas
        CaracteristicasTecnicas caracteristicas_Tecnicas = new
                CaracteristicasTecnicas (reflejos_Piloto, agresividad_Piloto,
                                         paciencia_Piloto, valentia_Piloto) ;
        // Declaramos el objeto Piloto
        /*Piloto modificar_Piloto = new Piloto (nombre_Piloto, apellidos_Piloto,
                                              datos_Personales, puntos_Piloto,
                                              valoracion_Piloto, sueldo_Piloto,
                                              caracteristicas_Tecnicas) ;*/
        Piloto modificar_Piloto = new Piloto (nombre_Piloto, apellidos_Piloto,
                                              datos_Personales, puntos_Piloto,
                                              caracteristicas_Tecnicas) ;
        //
        System.out.println("Longitud de Array Modificación: " + longitudArray) ;
        boolean encontrado = false ;
        for (int j=0; j<longitudArray; j++) {
            Piloto pilotoLista = (Piloto) arrayPilotos.get(j) ;
            String nombre_Piloto_Lista = pilotoLista.getNombre() ;
            String apellidos_Piloto_Lista = pilotoLista.getApellidos() ;
            String nombreCompleto_Lista = nombre_Piloto_Lista + apellidos_Piloto_Lista ;
            String nombreCompleto_Form = nombre_Piloto + apellidos_Piloto ;
            encontrado = nombreCompleto_Lista.equals(nombreCompleto_Form) ;
            if (encontrado) {
                System.out.println("Encontrado Modificación");
                arrayPilotos.remove(j);
                arrayPilotos.add(j,modificar_Piloto) ;
                metodo.borrarFichero(nombreFichero) ;
                metodo.escribirFichero(nombreFichero, arrayPilotos);
            }
            obtenerValoracion();
        }
        }else{
            ventanaAviso.mostrarError(this, "Las características técnicasdeben de tener un valor entre 0 y 5", "Error modifica piloto"); 
        }
        }catch (NumberFormatException nE){
            ventanaAviso.mostrarError(this, "Las características técnicas, los datos personales, los puntos y el sueldo deben de ser numéricos", "Error modifica piloto");
        }
    }//GEN-LAST:event_modificarPilotoActionPerformed

    private void jTextReflejosFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextReflejosFocusLost
         obtenerValoracion();
    }//GEN-LAST:event_jTextReflejosFocusLost

    private void jTextAgresividadFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextAgresividadFocusLost
        obtenerValoracion();
    }//GEN-LAST:event_jTextAgresividadFocusLost

    private void jTextPacienciaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextPacienciaFocusLost
         obtenerValoracion();
    }//GEN-LAST:event_jTextPacienciaFocusLost

    private void jTextValentiaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextValentiaFocusLost
         obtenerValoracion();
    }//GEN-LAST:event_jTextValentiaFocusLost
    
    public void cargarPilotos() {
        System.out.println("REGISTROS EN EL FICHERO CARGAR COMBOS") ;
        pilotos.addItem("");
        ArrayList<String> listadoPilotos = metodo.listadoPilotos() ;
        for (int j=0; j<listadoPilotos.size(); j++) {
            pilotos.addItem(listadoPilotos.get(j)) ;
        }
    }
    
    public void obtenerValoracion() {
         try{
              double reflejos_Piloto=0;
              double agresividad_Piloto=0;
              double paciencia_Piloto =0;
              double valentia_Piloto=0;
             if(!jTextReflejos.getText().isEmpty()){
                 reflejos_Piloto = Double.parseDouble(jTextReflejos.getText()) ;
             }
             if(!jTextAgresividad.getText().isEmpty()){
                 agresividad_Piloto = Double.parseDouble(jTextAgresividad.getText()) ;
             }  
             if(!jTextPaciencia.getText().isEmpty()){
                paciencia_Piloto = Double.parseDouble(jTextPaciencia.getText()) ; 
             }  
             if(!jTextValentia.getText().isEmpty()){   
                valentia_Piloto = Double.parseDouble(jTextValentia.getText()) ;
             }
             double valoracion_Piloto = reflejos_Piloto + agresividad_Piloto + paciencia_Piloto + valentia_Piloto ;
                valoracionPiloto.setText(String.format("%.1f",valoracion_Piloto)) ;
                double sueldo_Piloto = valoracion_Piloto * 50 ;
                sueldoPiloto.setText(String.format("%.1f",sueldo_Piloto)) ;
            
         }catch(NumberFormatException nE){
             ventanaAviso.mostrarError(this, "Las características técnicas, los datos personales, los puntos y el sueldo deben de ser numéricos", "Error añadir piloto"); 
         }
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ModificarPiloto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ModificarPiloto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ModificarPiloto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ModificarPiloto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ModificarPiloto().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField alturaPiloto;
    private javax.swing.JTextField apellidosPiloto;
    private javax.swing.JButton cancelarModificacion;
    private javax.swing.JTextField edadPiloto;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField jTextAgresividad;
    private javax.swing.JTextField jTextPaciencia;
    private javax.swing.JTextField jTextReflejos;
    private javax.swing.JTextField jTextValentia;
    private javax.swing.JButton modificarPiloto;
    private javax.swing.JTextField nombrePiloto;
    private javax.swing.JTextField pesoPiloto;
    private javax.swing.JComboBox pilotos;
    private javax.swing.JTextField puntosPiloto;
    private javax.swing.JTextField sueldoPiloto;
    private javax.swing.JTextField valoracionPiloto;
    // End of variables declaration//GEN-END:variables
}
